<template>
	<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.pagePath)" v-if="(index==0 && !isSh) || index !=0">
			<image class="item-img" :src="item.selectedIconPath" v-if="current == index"></image>
			<image class="item-img" :src="item.iconPath" v-else></image>
			<view class="item-name" :class="{'tabbarActive': current == index}" v-if="item.text">{{item.text}}
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		name: "tabbarxsd",
		props: ['current', "forceUpdate"],
		data() {
			return {
				isSh:false,
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
						"text": "服务",
						"pagePath": "/pages/index/index",
						"iconPath": "/static/tabbar/index.png",
						"selectedIconPath": "/static/tabbar/select_index.png"
					},
					{
						"text": "天商",
						"pagePath": "/pages/business/business",
						"iconPath": "/static/tabbar/business.png",
						"selectedIconPath": "/static/tabbar/select_business.png"
					},
					{
						"text": "购物车",
						"pagePath": "/pages/cart/cart",
						"iconPath": "/static/tabbar/cart.png",
						"selectedIconPath": "/static/tabbar/select_cart.png"
					},
					{
						"text": "消息",
						"pagePath": "/pages/message/message",
						"iconPath": "/static/tabbar/message.png",
						"selectedIconPath": "/static/tabbar/select_message.png"
					},
					{
						"text": "我的",
						"pagePath": "/pages/mine/mine",
						"iconPath": "/static/tabbar/mine.png",
						"selectedIconPath": "/static/tabbar/select_mine.png"
					}
				],
			}
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 0;
						}
					})
				}
			});
			this.getcheckApply()
		},
		methods: {
			getcheckApply() {
				// 类型:1=华为,2=荣耀,3=小米,4=OPPO,5=VIVO,6=三星,7=苹果
				let data_type = 1
				if(uni.getSystemInfoSync().brand){
					const ishuawei = uni.getSystemInfoSync().brand.toLowerCase().includes('huawei');
					const ishonor = uni.getSystemInfoSync().brand.toLowerCase().includes('honor');
					const isxiaomi = uni.getSystemInfoSync().brand.toLowerCase().includes('xiaomi');
					const isoppo = uni.getSystemInfoSync().brand.toLowerCase().includes('oppo');
					const isvivo = uni.getSystemInfoSync().brand.toLowerCase().includes('vivo');
					const issamsung = uni.getSystemInfoSync().brand.toLowerCase().includes('samsung'); //三星
					const isiphone = uni.getSystemInfoSync().brand.toLowerCase().includes('iphone');
					if (ishuawei) data_type = 1
					if (ishonor) data_type = 2
					if (isxiaomi) data_type = 3
					if (isoppo) data_type = 4
					if (isvivo) data_type = 5
					if (issamsung) data_type = 6
					if (isiphone) data_type = 7
				}
				httpRequest.request('/api/index/checkApply', 'GET', {
					data_type,
					version_code:uni.getSystemInfoSync().appVersionCode
				}).then(res => {
					if(res.data.is_apply){
						this.isSh = true
						uni.setStorageSync('jumpPath','/pages/business/business')
					}else{
						uni.setStorageSync('jumpPath','/pages/index/index')
					}
				})
			},
			tabbarChange(pagePath) {
				uni.switchTab({
					url: pagePath
				})
			}
		}

	}
</script>

<style lang="scss">
	.item-img {
		height: 40rpx;
		width: 40rpx;
		margin: auto;
		display: block;
	}

	// .fabuimg{
	// 	position: absolute;
	// 	bottom: 36rpx;
	// 	left: 10rpx;
	// 	height: 90rpx;
	// 	width: 90rpx;
	// 	margin: auto;
	// 	display: block;
	// 	background-color: #fff;
	// 	background-size: 80rpx 80rpx;
	// 	border-radius: 50%;
	// 	// box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.05);
	// }

	.tabbar {
		display: flex;
		justify-content: space-around;
		align-items: flex-end;
		background: #FFFFFF;
		border-radius: 0rpx;
		/* #ifdef MP-WEIXIN */
		height: 140rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 140rpx;
		/* #endif */
		/* #ifdef APP-PLUS */
		height: 140rpx;
		/* #endif */
		padding: 0;
		// padding: 0 50rpx 0 50rpx;
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		bottom: 0;
		overflow: inherit;
		z-index: 100;
		// box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.05);
	}

	.tabbar-item {
		margin-bottom: 30rpx;
		width: 250rpx;
		position: relative;
	}

	.item-name {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		text-align: center;
		color: #666666;
		margin-top: 14rpx;
	}

	.tabbarActive {
		color: #F3271C;
		text-align: center;
	}
</style>